import { getRequest } from "@/api/request";
import { AxiosResponse } from "axios";
const REQUEST_URL = {
  captchaLogin: "/login/cellphone",
  captcha: "/captcha/sent",
};

export interface CaptchaLogin {
  phone: number | string;
  captcha: number | string;
}

const handleCaptchaResult = (res: AxiosResponse) => {
  console.log(res);
  return res;
};

const handleLoginResult = (res: AxiosResponse) => {
  console.log(res);
  return res;
};

export const getCaptcha = (phone: number) => {
  return getRequest(REQUEST_URL.captcha + `?phone=${phone}`).then(
    handleCaptchaResult
  );
};

export const captchaLogin = (params: CaptchaLogin) => {
  return getRequest(
    REQUEST_URL.captchaLogin +
      `?phone=${params.phone}&captcha=${params.captcha}`
  ).then(handleLoginResult);
};
